package com.unisound.tracelog.common.model.span;

public class Span {
    private Long spanId;
    private Long traceId;
    private Long parentSpanId;
    private String name;
    private String serviceName;
    private Integer type = 0;
    private long execTime;
    private String content;



    private boolean input;
    private Integer resultFlag;

    /**
     * 耗时(ms)
     */
    private long elapsedTimeMillis;

    public Span(Long spanId, Long traceId, Long parentSpanId, String name, String serviceName, Integer type, long execTime, String content, boolean input, Integer resultFlag, long elapsedTimeMillis) {
        this.spanId = spanId;
        this.traceId = traceId;
        this.parentSpanId = parentSpanId;
        this.name = name;
        this.serviceName = serviceName;
        this.type = type;
        this.execTime = execTime;
        this.content = content;
        this.input = input;
        this.resultFlag = resultFlag;
        this.elapsedTimeMillis = elapsedTimeMillis;
    }

    public Span() {
    }

    public static Span startSpan(Long spanId, Long traceId, Long parentSpanId, String name, String serviceName, Integer type, String content) {
        return new Span(spanId, traceId, parentSpanId, name, serviceName, type, System.currentTimeMillis(), content, true, 0, 0L);
    }

    public static Span endSpan(Long spanId, Long traceId, Long parentSpanId, String name, String serviceName, Integer type, String content) {
        return new Span(spanId, traceId, parentSpanId, name, serviceName, type, System.currentTimeMillis(), content, false, 0, 0L);
    }

    public Long getSpanId() {
        return spanId;
    }

    public Long getTraceId() {
        return traceId;
    }

    public Long getParentSpanId() {
        return parentSpanId;
    }

    public String getName() {
        return name;
    }

    public String getServiceName() {
        return serviceName;
    }

    public long getExecTime() {
        return execTime;
    }

    public String getContent() {
        return content;
    }

    public boolean isInput() {
        return input;
    }

    public Integer getResultFlag() {
        return resultFlag;
    }

    public void setSpanId(Long spanId) {
        this.spanId = spanId;
    }

    public void setTraceId(Long traceId) {
        this.traceId = traceId;
    }

    public void setParentSpanId(Long parentSpanId) {
        this.parentSpanId = parentSpanId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public void setExecTime(long execTime) {
        this.execTime = execTime;
    }

    public void setContent(String content) {
        this.content = content == null ? "" : content;
    }

    public void setInput(boolean input) {
        this.input = input;
    }

    public void setResultFlag(Integer resultFlag) {
        this.resultFlag = resultFlag;
    }

    public long getElapsedTimeMillis() {
        return elapsedTimeMillis;
    }

    public void setElapsedTimeMillis(long elapsedTimeMillis) {
        this.elapsedTimeMillis = elapsedTimeMillis;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }
}
